package org.sbbs.app.security.dao.hibernate;

import java.util.List;

import org.sbbs.app.security.dao.UserDao;
import org.sbbs.app.security.model.User;
import org.sbbs.base.dao.hibernate.BaseDaoHibernate;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Repository;

@Repository("userDao")
public class UserDaoHibernate extends BaseDaoHibernate<User, Long>
		implements
			UserDao {

	public UserDaoHibernate() {
		super(User.class);
	}

	@Override
	public User loadUserByUsername(String username)
			throws UsernameNotFoundException {
		List users = getHibernateTemplate().find("from User where username=?",
				username);
		if (users == null || users.isEmpty()) {
			throw new UsernameNotFoundException("user '" + username
					+ "' not found...");
		} else {
			return (User) users.get(0);
		}
	}
}
